package life.huangzhi.community.community.service;

import life.huangzhi.community.community.mapper.UserMapper;
import life.huangzhi.community.community.model.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserService {
    @Resource
    UserMapper userMapper;
    public void createOrUpdate(User user){
        User dbuser = userMapper.findByAccountId(user.getAccountId());
        if (dbuser ==null){
            //插入
            user.setGmtCreate(System.currentTimeMillis());
            user.setGmtModified(user.getGmtCreate());
            userMapper.insertUser(user);
        }else{
            //更新
            dbuser.setGmtModified(System.currentTimeMillis());
            dbuser.setAvatarUrl(user.getAvatarUrl());
            dbuser.setToken(user.getToken());
            userMapper.updateUser(dbuser);
        }
    }
}
